<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%@ page import="com.starbaba.core.web.constant.WebConstants"%>
<%@ page import="com.starbaba.system.user.model.UserVO"%>
<!DOCTYPE html>
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<%@ include file="/common/common-css.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}
</style>
</head>
<body class="no-skin">
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display: none" />
	<div class="page-content">
		<div class="page-header" style="margin-bottom: 0px; padding-bottom: 10px;"></div>

		<form id="queryForm" method="post" enctype="multipart/form-data">
		
			<input type="hidden" id="isFile" name="isFile" value="${sessionScope.USER_DATA_IS_INPUT_TEMP }"/>
			
			<div class="page-content-area">
				<div class="row">
					<div class="col-sm-12">
						<div class="widget-box" style="border: 0px solid #ccc; border-top: none; border-bottom: none;">
							<div class="widget-header widget-header-blue widget-header-flat">
								<h4 class="widget-title">选择条件进行查询</h4>
								<div class="widget-toolbar">
									<a href="#" data-action="collapse"><i class="ace-icon fa fa-chevron-up"></i></a>
								</div>
							</div>

							<div class=" widget-body">
								<div class="widget-main">
			                        <input type="hidden" id="suffix" name="suffix">
									<div class="form-group col-xs-12 col-sm-4">
										<label class="col-sm-2 control-label"  style="text-align:right"  for="activity">手机号：</label>
										<div class="col-sm-8">
											<div class="input-daterange input-group col-sm-12">
												<input type="text" name="phone" class="form-control text-left">
											</div>
										</div>
									</div>

									<div class="form-group col-xs-12 col-sm-4 "> 
										<label class="col-sm-2 control-label"  style="text-align:right"  for="sex">申请时间:</label>
										<div class="col-sm-6">
											<div class="input-daterange input-group col-sm-12">
												<input type="text" data-date-format="yyyy-mm-dd hh:ii" class="fromDate date-picker input-sm form-control" style="padding-left:0px" name="applyStartTime">
												<span class="input-group-addon" style="width:6px">
													<i class="fa fa-exchange"></i>
												</span>
												<input type="text" data-date-format="yyyy-mm-dd hh:ii" class="endDate date-picker input-sm form-control" style="padding-left:0px" name="applyEndTime">
											</div>
										</div>
									 </div>

									<div class="form-group col-xs-12 col-sm-4 "> 
										<label class="col-sm-2 control-label"  style="text-align:right"  for="sex">放贷时间:</label>
										<div class="col-sm-6">
											<div class="input-daterange input-group col-sm-12">
												<input type="text" data-date-format="yyyy-mm-dd hh:ii" class="fromDate date-picker input-sm form-control" style="padding-left:0px" name="loanStartTime">
												<span class="input-group-addon" style="width:6px">
													<i class="fa fa-exchange"></i>
												</span>
												<input type="text" data-date-format="yyyy-mm-dd hh:ii" class="endDate date-picker input-sm form-control" style="padding-left:0px" name="loanEndTime">
											</div>
										</div>
									 </div>

									<div class="form-group col-xs-12 col-sm-4">
										<label class="col-sm-2 control-label"  style="text-align:right">产品：</label>
										 <div class="col-sm-4">
											<div class="input-daterange input-group col-sm-12">
													<s:select id="prdList" name="prd_id" list="%{paramsMap.prdList}" listKey="prd_id" listValue="prd_name" 
													headerKey="" headerValue="------请选择------" cssClass="form-control"></s:select>
											</div>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4">
										<label class="col-sm-2 control-label"  style="text-align:right">渠道：</label>
										 <div class="col-sm-4">
											<div class="input-daterange input-group col-sm-12">
													<s:select id="channelList" name="channel" list="%{paramsMap.channelList}" listKey="channel" listValue="channel_name" 
													headerKey="" headerValue="------请选择------" cssClass="form-control"></s:select>
											</div>
										</div>
									</div>
									<div class="form-group col-xs-12 col-sm-4">
										<label class="col-sm-2 control-label"  style="text-align:right">合作方：</label>
										 <div class="col-sm-4">
											<div class="input-daterange input-group col-sm-12">
													<s:select id="activityList" name="activity" list="%{paramsMap.activityList}" listKey="activity_name" listValue="activity_name" 
													headerKey="" headerValue="------请选择------" cssClass="form-control"></s:select>
											</div>
										</div>
									</div>

								</div>
								<!-- /.widget-main -->
							</div>
							<!-- /.widget-body -->
						</div>
						<!-- /.widget-box -->
					</div>
					<!-- /.col-sm-12 -->
					
					<div class="col-md-12 center">
						<div class="clearfix form-actions">
						
							<button class="btn btn-purple  no-border" type="button"
								name="btn-query" onclick="query_any(2)" id="btn-query">
								<i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
								查询
							</button>
							&nbsp;&nbsp;&nbsp;
							<span id="upload"> 
								<input id="uploadfile_wx"name="upload" type="file" size="1" style="display: none" />
								<input id="uploadbtn_wx" type='button' class='btn' value='导入基础数据' />
							</span>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey  no-border" type="button"
								name="handlerecord" id="handlerecord">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
								确认录入所选项
							</button>
							&nbsp;&nbsp;&nbsp;
							<button class="btn btn-grey  no-border" type="button"
								name="cleanFileBuf" id="cleanFileBuf">
								<i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
								清除文件缓存
							</button>
							
						</div>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<table id="jquery-table" class="table table-striped table-bordered table-hover"></table>
					</div>
					<!-- /.col -->
				</div>
				<!-- /.row -->

			</div>
			<!-- /.page-content-area -->
		</form>
	</div>
	<!-- /.page-content -->

<%@ include file="/common/common-js.jsp"%>
<script type="text/javascript" src="${ctx}/js/call_func.js"></script>
<script type="text/javascript"
	src="${ctx}/ace/js/jquery.dataTables.min.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">

jQuery(function($) {
	if ("" != "${paramsMap.message}") {
		message = "${paramsMap.message}";
		alert(message);
	}
});

// 上传按钮时间绑定
$('#uploadbtn_wx').click(function() {
	$('#uploadfile_wx').trigger('click');
});
	
// 上传事件
$('#uploadfile_wx').change(function() {
	var filename = $("#uploadfile_wx").val();
	var extStart = filename.lastIndexOf(".");
	var ext = filename.substring(extStart+1, filename.length).toUpperCase();
	
	if ("XLSX" != ext && "XLS" != ext) {
		alert("文件格式错误,请导入excel文件");
		return;
	}
	$("#suffix").val(ext);
	var file = this.files[0];
	var r = new FileReader();
	r.readAsDataURL(file);
	$(r).load(function() {
		var $form = document.forms["queryForm"];
		$form.action = ctx + "/userdatainput/upload.action";
		$form.submit();
	});
});

$(document).ready(function() {
	query_any();
});
	
// 确定录入按钮事件
$('#handlerecord').click(function() {
	var isFileUp = $("#isFile").val();
	if(isFileUp == 0){
		alert("请上传文件");
		return;
	}
	if (window.confirm('确认导入数据')) {
		var ids = "-1";
		$(".cbox").each(function(){
			if($(this).is(':checked')){
				var id = $(this).val();
				ids = ids + "," + id;
			}
		});
		if(ids=="-1"){
			alert("无勾选数据");
			return;
		}
		var data = $('#queryForm').serializeObject();
		$.ajax({
			"type" : "POST",
			"data" : {"ids":ids},
			"dataType" : 'json',
			"url" : ctx + '/userdatainput/uploadToDB.action',
			"timeout" : 300000,
			"success" : function(data) {
					$("#isFile").val(0);
					alert(data.message);
					query_any();
			},
			"error" : function() {
				alert("处理失败");
			}
		});
	}
});

// 清除上传文件按钮事件
$('#cleanFileBuf').click(function() {
	var data = $('#queryForm').serializeObject();
	$.ajax({
		"type" : "POST",
		"dataType" : 'json',
		"url" : ctx + '/userdatainput/cleanBuf.action',
		"timeout" : 300000,
		"success" : function(data) {
				$("#isFile").val(0);
				alert(data.message);
				query_any();
		},
		"error" : function() {
			alert("处理失败");
		}
	});
});

//【查询】按钮Click事件
	function query_any() {
		$(".load_bg").removeAttr("style");
		$(".load_img").removeAttr("style");
		if (jqTable != null) {
			jqTable.fnDraw();
		} else {
			loaddata();
		}
		$("#delete_hr").attr("style", "margin-top:0px;margin-bottom:20px;display:block");
	}
	var jqTable = null;
	var loaddata = function() {
		jQuery(function($) {
			jqTable = $('#jquery-table').dataTable(
					{
						"columnDefs" : [
									{
										"title" : '<input type="checkbox" id="checkAll"/>',	
										"name" : "position",
										"data" : "position",
										"targets" : [ 0 ],
										"bSortable" : false,
										"render" : function(value, type, row) { // 返回自定义内容
											return " <input type='checkbox' class='cbox' value='" + row.id + "'/> ";
										}
									},
									{
										"title" : '所属产品',
										"targets" : [ 1 ],
										"name" : "prd_name",
										"data" : "prd_name", 
										"bSortable" : false,
									},
									{
										"title" : '所属渠道',
										"targets" : [ 2 ],
										"name" : "channel_name",
										"data" : "channel_name", 
										"bSortable" : false,
									},
									{
										"title" : '合作方ID',
										"targets" : [ 3 ],
										"name" : "activity_id",
										"data" : "activity_id", 
										"bSortable" : false,
									},
									{
										"title" : "合作方名",
										"name" : "activity_name",
										"data" : "activity_name",
										"targets" : [ 4 ],
										"bSortable" : false,
									},
									{
										"title" : "客户手机号",
										"name" : "phone",
										"data" : "phone",
										"targets" : [ 5 ],
										"bSortable" : false,
									},
									{
										"title" : "注册时间",
										"name" : "register_date",
										"data" : "register_date",
										"targets" : [ 6 ],
										"bSortable" : false,
									},
									{
										"title" : "提交申请时间",
										"name" : "apply_date",
										"data" : "apply_date",
										"targets" : [ 7 ],
										"bSortable" : false,
									},
									{
										"title" : "放贷时间",
										"name" : "loan_date",
										"data" : "loan_date",
										"targets" : [ 8 ],
										"bSortable" : false,
									},
									{
										"title" : "贷款金额",
										"name" : "loan_money",
										"data" : "loan_money",
										"targets" : [ 9 ],
										"bSortable" : false,
									},
									{
										"title" : "结算金额",
										"name" : "settlement_money",
										"data" : "settlement_money",
										"targets" : [ 10 ],
										"bSortable" : false,
									},
									{
										"title" : "操作人",
										"name" : "operator",
										"data" : "operator",
										"targets" : [ 11 ],
										"bSortable" : false,
									},
									{
										"title" : "创建时间",
										"name" : "ctime",
										"data" : "ctime",
										"targets" : [ 12 ],
										"bSortable" : false,
									}
							],
							"sAjaxSource" : ctx + "/userdatainput/queryList.action",
							"fnServerData" : function(sSource, aoData,
									fnCallback) {//从服务器请求数据
								var data = $('#queryForm').serializeObject();
								data.aoData = JSON.stringify(aoData);
								$.ajax({
									"dataType" : 'json',
									"type" : "POST",
									"url" : sSource,
									"data" : data,
									"success" : function(resp) {
										fnCallback(resp);
										initListPage();
										$(".load_bg").attr("style",
												"display:none");
										$(".load_img").attr("style",
												"display:none");
									},
									"error" : function(XMLHttpRequest,
											textStatus, errorThrown) {
										$(".load_bg").attr("style",
												"display:none");
										$(".load_img").attr("style",
												"display:none");
										alert('请求服务器错误,请刷新重试！！');//错误提示，包括服务器重启导致的session失效
									},
								});
							},
							"sScrollXInner" : "100%",
							"sScrollY" : "100%",//如果不设置，IE会有问题
							"aaSorting" : [ [ 1, "desc" ] ]
						});
			});
		}

//全选Checkbox事件
$(document).on('click', '#checkAll' , function(){
	var that = this;
	$("input[class='cbox']").each(function(){
		this.checked = that.checked;
		$(this).closest('tr').toggleClass('selected');
	});
});
	
//时间组件
jQuery(function() {
	$(".date-picker").datepicker({
		autoclose : true,
		format : 'yyyy-mm-dd'
	});
	$("#prdList").combobox();
	$("#channelList").combobox();
	$("#activityList").combobox();
});
	
</script>

</body>
</html>